import Vue from "vue";
import VueRouter from "vue-router";

import Login from "../views/home/login.vue";

import DepartmentList from "../views/department/departmentList.vue";

import WorkflowList from "../views/workflow/workflowList.vue";
import WorkflowManager from "../views/workflow/workflowManager.vue";

import MatchList from "../views/match/matchList.vue";
import MatchFrom from "../views/match/matchFrom.vue";
import MatchBindDepartment from "../views/match/matchBindDepartment.vue";

import AuditList from "../views/audit/auditList.vue";
import AuditDetail from "../views/audit/auditDetail.vue";
import AuditAllList from "../views/audit/auditAllList.vue";

import Auditlistpuss from '../views/audit/Auditlistpuss.vue'
import Auditedlist from '../views/audit/Auditedlist.vue'
import certificationList from '../views/audit/certificationList.vue'
import certificationdlist from '../views/audit/certificationdlist.vue'

import EnrollList from "../views/enroll/enrollList.vue";
import AddEnroll from "../views/enroll/addEnroll.vue";
import Singleadd from '../views/enroll/singleadd.vue';

import AreaManager from "../views/area/areaManager.vue";

import PassManager from "../views/pass/passManager.vue";

import CompanyManager from "../views/company/companyManager.vue";

import UserManager from "../views/user/userManager.vue";

import blacklist from '../views/blacklist/blacklist.vue'
Vue.use(VueRouter);

const routes = [
  // home
  {
    path: "/",
    name: "Home",
    redirect: "/audit/list",
  }, // 首页
  {
    path: "/login",
    name: "Login",
    component: Login,
    meta: {
      title: "登录",
    },
  }, // 登录
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 赛事名称
  {
    path: "/department/list",
    name: "DepartmentList",
    component: DepartmentList,
    meta: {
      title: "部门管理",
    },
  }, // 部门管理
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 流程
  {
    path: "/workflow/list",
    name: "WorkflowList",
    component: WorkflowList,
    meta: {
      title: "流程管理",
    },
  }, // 流程管理
  {
    path: "/workflow/node",
    name: "WorkflowManager",
    component: WorkflowManager,
    meta: {
      title: "节点管理",
    },
  }, // 节点管理
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 赛事名称
  {
    path: "/match/list",
    name: "MatchList",
    component: MatchList,
    meta: {
      title: "赛事名称管理",
    },
  }, // 赛事名称管理blacklist
  {
    path: "/blacklist/list",
    name: "blacklist",
    component: blacklist,
    meta: {
      title: "黑名单",
    },
  },
  {
    path: "/match/from",
    name: "MatchFrom",
    component: MatchFrom,
    meta: {
      title: "赛事名称管理",
    },
  }, // 赛事名称管理--新增/编辑
  {
    path: "/match/bindDepartment",
    name: "MatchBindDepartment",
    component: MatchBindDepartment,
    meta: {
      title: "关联部门",
    },
  }, // 赛事名称管理--关联部门
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 报名
  {
    path: "/match/audit/list",
    name: "AuditList",
    component: AuditList,
    meta: {
      title: "报名名单",
    },
  }, // 报名名单-审核列表
  {
    path: "/match/audit/detail",
    name: "AuditDetail",
    component: AuditDetail,
    meta: {
      title: "报名详情",
    },
  }, // 报名详情
  {
    path: "/audit/list",
    name: "AuditAllList",
    component: AuditAllList,
    meta: {
      title: "报名审核",
    },
  }, // 报名审核
  {
    path: "/enroll/list",
    name: "EnrollList",
    component: EnrollList,
    meta: {
      title: "报名名单",
    },
  }, // 报名名单
  {
    path: "/enroll/add",
    name: "AddEnroll",
    component: AddEnroll,
    meta: {
      title: "新增报名",
    },
  }, // 新增报名

  {
    path: "/enroll/singleadd",
    name: "Singleadd",
    component: Singleadd,
    meta: {
      title: "单一新增报名",
    },
  }, // 单一新增报名
  //
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 权限区域
  {
    path: "/match/area/list",
    name: "AreaManager",
    component: AreaManager,
    meta: {
      title: "权限区域管理",
    },
  }, // 权限区域管理
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 证件种类
  {
    path: "/match/pass/list",
    name: "PassManager",
    component: PassManager,
    meta: {
      title: "证件种类管理",
    },
  }, // 证件种类管理
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 公司
  {
    path: "/match/bindDepartment/company/list",
    name: "CompanyManager",
    component: CompanyManager,
    meta: {
      title: "公司管理",
    },
  }, // 公司管理
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  /****************************************************************/
  // 用户
  {
    path: "/user/list",
    name: "UserManager",
    component: UserManager,
    meta: {
      title: "用户管理",
    },
  }, // 用户管理

  {
    path: "/Auditlistpuss/list",
    name: "Auditlistpuss",
    component: Auditlistpuss,
    meta: {
      title: "待审核",
    },
  },


  {
    path: "/Auditedlist/list",
    name: "Auditedlist",
    component: Auditedlist,
    meta: {
      title: "已审核",
    },
  },

  {
    path: "/certificationList/list",
    name: "certificationList",
    component: certificationList,
    meta: {
      title: "制证名单",
    },
  },
  {
    path: "/certificationdlist/dlist",
    name: "certificationdlist",
    component: certificationdlist,
    meta: {
      title: "制证详情",
    },
  },
];

const router = new VueRouter({
  mode: "history",
  base: "/admin/",
  routes,
});

// 全局路由守卫
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }

  // 需要登录的页面
  const nextRoute = [
    "Home",

    "DepartmentList",

    "WorkflowList",
    "WorkflowManager",

    "MatchList",
    "MatchFrom",
    "MatchBindDepartment",

    "AuditList",
    "AuditDetail",
    "AuditAllList",
    "EnrollList",
    "AddEnroll",
    "Singleadd",

    "AreaManager",

    "PassManager",

    "CompanyManager",

    "UserManager",

    "blacklist",

    "Auditlistpuss",
    "Auditedlist",
    "certificationList",
    "certificationdlist"
  ];
  let isLogin = localStorage.getItem("ADMINLOGINTOKEN"); // 判断是否登录，本地存储有用户数据则视为已经登录
  // 未登录状态；当路由到 nextRoute 指定页时，跳转至 登录
  if (nextRoute.indexOf(to.name) >= 0) {
    // 检测是否登录的页面
    if (!isLogin) {
      // 如果未登录（本地存储无用户数据），并且要跳到登录页面
      if (from.name === "Login") {
        next("/login");
        return;
      }
      // 登录后，跳到到当前页面
      router.push({
        name: "Login",
      });
    }
  }

  // 已登录状态；当路由到 登录 时，跳转至 首页
  if (to.name === "Login") {
    if (isLogin) {
      next("/");
      return;
    }
  }
  next(); // 必须使用 next ,执行效果依赖 next 方法的调用参数
});
export default router;
